﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using BusLogic;

public partial class OrderManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            get_All_Order();
        }
    }

    protected void lbtDelete_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in OrderRepeater.Items)
        {
            CheckBox cb = (CheckBox)item.FindControl("cbxCheckOrder");

            if (cb.Checked == true)
            {
                TextBox txtOrderId = (TextBox)item.FindControl("txtOrderId");
                //BusLogic.Product.remove_PRODUCT(int.Parse(txtOrderId.Text));
                Order.remove_ORDER_DETAIL(int.Parse(txtOrderId.Text));
                Order.remove_ORDER(int.Parse(txtOrderId.Text));
            }
        }
        get_All_Order();
        cbxCheckALLOrder.Checked = false;
    }

    public void get_All_Order()
    {
        cpPaging.PageSize = 30;
        cpPaging.DataSource = BusLogic.Order.get_ALL_ORDER().Tables[0].DefaultView;
        cpPaging.BindToControl = OrderRepeater;
        OrderRepeater.DataSource = cpPaging.DataSourcePaged;
        OrderRepeater.DataBind();
    }

    protected void cbxCheckALLOrder_CheckedChanged(object sender, EventArgs e)
    {
        if (!cbxCheckALLOrder.Checked)
        {
            foreach (RepeaterItem item in OrderRepeater.Items)
            {
                CheckBox cb = (CheckBox)item.FindControl("cbxCheckOrder");
                cb.Checked = false;

            }
        }
        else
        {
            foreach (RepeaterItem item in OrderRepeater.Items)
            {
                CheckBox cb = (CheckBox)item.FindControl("cbxCheckOrder");
                cb.Checked = true;
            }
        }
    }

    public string get_Type_CheckOut(int iTypeCheckOut)
    {
        string sTypeCheckOut = "";
        switch (iTypeCheckOut)
        {
            case 1:
                sTypeCheckOut = "Bưu điện";
                break;
            case 2:
                sTypeCheckOut = "Ngân hàng";
                break;
            case 3:
                sTypeCheckOut = "Clerm";
                break;
            case 4:
                sTypeCheckOut = "Nơi nhận hàng";
                break;            
        }

        return sTypeCheckOut;
    }

    public string get_Image_Product(object data)
    {
        string sImageUrl = data.ToString();

        String[] sArrImage = sImageUrl.Split(new Char[] { ';' });

        return sArrImage[0];
    }

}
